using MicroMsg.Common.Utils;
using MicroMsg.Resource.@string;
using MicroMsg.UI.UserContrl;
using MicroMsg.UI.Util;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using Microsoft.Xna.Framework.Media;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
namespace MicroMsg.UI.Page
{
	public class MultiPhotoChooser : BasePage
	{
		public class Group<T> : ObservableCollection<T>
		{
			public string Key
			{
				get;
				set;
			}
			public bool HasItems
			{
				get
				{
					return 0 != base.get_Count();
				}
				set
				{
				}
			}
			public Group(string name, IEnumerable<T> items)
			{
				this.Key = name;
				if (items != null)
				{
					using (IEnumerator<T> enumerator = items.GetEnumerator())
					{
						while (enumerator.MoveNext())
						{
							T current = enumerator.get_Current();
							base.Add(current);
						}
					}
				}
			}
			public override bool Equals(object value)
			{
				MultiPhotoChooser.Group<T> group = value as MultiPhotoChooser.Group<T>;
				return group != null && this.Key.Equals(group.Key);
			}
			public override int GetHashCode()
			{
				return base.GetHashCode();
			}
		}
		private MultiPhotoChooserConfig config;
		private ObservableCollection<MultiPhotoChooser.Group<PhotoListLine>> mListGroup;
		private MediaLibrary mediaLibrary = new MediaLibrary();
		public static List<Picture> sSelectedPictures = new List<Picture>();
		private MultiPhotoChooserResult resultData;
		private bool isChangedInAlbum;
		private PictureAlbum lastAlbum;
		private static Dictionary<Picture, List<ChooserImage>> pic_views_map;
		private ApplicationBar mBar;
		private ApplicationBarIconButton mOkBarButton;
		private ApplicationBarIconButton mRotateButton;
		private WriteableBitmap rotateImage;
		private WriteableBitmap rotateThumb;
		private int mTurnAngle;
		internal Grid LayoutRoot;
		internal Grid ContentPanel;
		internal TextBlock txtTitle;
		internal Grid MainLayout;
		internal Pivot mPivotControl;
		internal Button btnTimeLineTab;
		internal Grid timeLineView;
		internal LongListSelector mTimeLineLongList;
		internal Button btnAlbumsTab;
		internal Grid AlbumsView;
		internal WrapPanel AlbumsLayout;
		internal StackPanel AlbumPicsLayout;
		internal DynamicTextBlock txtAlbumTitle;
		internal ListBox AlbumPicsListBox;
		internal ScrollViewer resultPicScrollViewer;
		internal StackPanel resultPicLayout;
		internal ImageButton resultOKButton;
		internal ScrollViewer rotateLayout;
		internal Image image_0;
		private bool _contentLoaded;
		public MultiPhotoChooser()
		{
			this.InitializeComponent();
			MultiPhotoChooser.sSelectedPictures.Clear();
			MultiPhotoChooser.pic_views_map = new Dictionary<Picture, List<ChooserImage>>();
			base.add_Loaded(new RoutedEventHandler(this.MultiPhotoChooser_Loaded));
		}
		private void MultiPhotoChooser_Loaded(object sender, RoutedEventArgs e)
		{
			if (this.resultOKButton.border != null)
			{
				this.resultOKButton.border.set_Background(new SolidColorBrush(Colors.get_Transparent()));
			}
		}
		protected override void OnPageIn(object[] object_0)
		{
			if (object_0 != null && object_0.Length > 0)
			{
				this.config = (object_0[0] as MultiPhotoChooserConfig);
			}
			if (this.config == null)
			{
				MMMessageBox.Show("请传入配置参数", true, "确定").ReturnEvent = new DlgReturnEvent(this.finishPage);
				return;
			}
			if (this.config.CountLimit <= 0)
			{
				this.config.CountLimit = 1;
			}
			this.updateTitleCount();
			this.resultPicLayout.add_SizeChanged(new SizeChangedEventHandler(this.resultPicLayout_SizeChanged));
		}
		private void resultPicLayout_SizeChanged(object sender, SizeChangedEventArgs e)
		{
			if (e.get_NewSize().get_Width() > e.get_PreviousSize().get_Width())
			{
				this.resultPicScrollViewer.ScrollToHorizontalOffset(1500.0);
			}
		}
		private void finishPage(DlgReturnEventArg dlgReturnEventArg_0)
		{
			base.GoBack();
		}
		protected override void OnPageOut()
		{
		}
		private void btnTimeLineTab_Click(object sender, RoutedEventArgs e)
		{
			this.ToIndex(0, true);
		}
		private void btnAlbumsTab_Click(object sender, RoutedEventArgs e)
		{
			this.ToIndex(1, true);
		}
		public void ToIndex(int nIndex, bool bForceTo = false)
		{
			if (nIndex >= 0 && nIndex < this.mPivotControl.get_Items().get_Count() && bForceTo)
			{
				this.mPivotControl.SelectedIndex = nIndex;
			}
		}
		private void Pivot_SelectionChanged(object sender, SelectionChangedEventArgs e)
		{
			if (this.mPivotControl.SelectedIndex == 0)
			{
				if (this.mListGroup == null)
				{
					this.loadTimeLineDatas();
					return;
				}
			}
			else
			{
				if (this.mPivotControl.SelectedIndex == 1)
				{
					if (this.AlbumsLayout.get_Children().get_Count() == 0)
					{
						this.AlbumsLayout.get_Children().Clear();
						List<PictureAlbum> albums = this.getAlbums();
						using (List<PictureAlbum>.Enumerator enumerator = albums.GetEnumerator())
						{
							while (enumerator.MoveNext())
							{
								PictureAlbum current = enumerator.get_Current();
								AlbumItemView albumItemView = new AlbumItemView();
								albumItemView.ItemClick += new AlbumItemView.AlbumItemClick(this.albumItem_Click);
								albumItemView.SetAlbum(current);
								this.AlbumsLayout.get_Children().Add(albumItemView);
							}
							return;
						}
					}
					using (IEnumerator<UIElement> enumerator2 = this.AlbumsLayout.get_Children().GetEnumerator())
					{
						while (enumerator2.MoveNext())
						{
							UIElement current2 = enumerator2.get_Current();
							AlbumItemView albumItemView2 = current2 as AlbumItemView;
							if (albumItemView2 != null)
							{
								albumItemView2.ReSetSelectedCount();
							}
						}
					}
				}
			}
		}
		private void albumItem_Click(object sender, object object_0)
		{
			AlbumItemView albumItemView = sender as AlbumItemView;
			if (albumItemView == null)
			{
				return;
			}
			PictureAlbum pictureAlbum = albumItemView.get_Tag() as PictureAlbum;
			if (pictureAlbum == null)
			{
				return;
			}
			this.loadPicsOfAlbum(pictureAlbum);
			this.MainLayout.set_Visibility(1);
			this.AlbumPicsLayout.set_Visibility(0);
			this.txtAlbumTitle.Text = pictureAlbum.get_Name();
		}
		protected override void OnBackKeyPress(CancelEventArgs cancelEventArgs_0)
		{
			if (this.rotateLayout.get_Visibility() == null)
			{
				this.rotateLayout.set_Visibility(1);
				this.ContentPanel.set_Visibility(0);
				this.mBar.set_IsVisible(false);
				cancelEventArgs_0.set_Cancel(true);
				return;
			}
			if (this.AlbumPicsLayout.get_Visibility() == null)
			{
				this.MainLayout.set_Visibility(0);
				this.AlbumPicsLayout.set_Visibility(1);
				cancelEventArgs_0.set_Cancel(true);
				if (this.isChangedInAlbum)
				{
					this.isChangedInAlbum = false;
					using (IEnumerator<UIElement> enumerator = this.AlbumsLayout.get_Children().GetEnumerator())
					{
						while (enumerator.MoveNext())
						{
							UIElement current = enumerator.get_Current();
							AlbumItemView albumItemView = current as AlbumItemView;
							if (albumItemView != null)
							{
								albumItemView.ReSetSelectedCount();
							}
						}
					}
					base.get_Dispatcher().BeginInvoke(delegate
					{
						this.loadTimeLineDatas();
					});
				}
			}
		}
		private void loadTimeLineDatas()
		{
			this.mListGroup = new ObservableCollection<MultiPhotoChooser.Group<PhotoListLine>>();
			this.mTimeLineLongList.ItemsSource = this.mListGroup;
			List<MultiPhotoChooser.Group<PhotoListLine>> tempListGroup = new List<MultiPhotoChooser.Group<PhotoListLine>>();
			Dictionary<string, List<Picture>> dictionary = new Dictionary<string, List<Picture>>();
			using (IEnumerator<Picture> enumerator = Enumerable.Reverse<Picture>(Enumerable.OrderBy<Picture, DateTime>(this.mediaLibrary.get_Pictures(), (Picture picture_0) => picture_0.get_Date())).GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					Picture current = enumerator.get_Current();
					string yearMonthDisplay = Util.GetYearMonthDisplay(current.get_Date());
					if (dictionary.ContainsKey(yearMonthDisplay))
					{
						List<Picture> list = dictionary.get_Item(yearMonthDisplay);
						list.Add(current);
					}
					else
					{
						List<Picture> list2 = new List<Picture>();
						list2.Add(current);
						dictionary.set_Item(yearMonthDisplay, list2);
					}
				}
			}
			using (Dictionary<string, List<Picture>>.KeyCollection.Enumerator enumerator2 = dictionary.get_Keys().GetEnumerator())
			{
				while (enumerator2.MoveNext())
				{
					string current2 = enumerator2.get_Current();
					List<PhotoListLine> list3 = new List<PhotoListLine>();
					List<Picture> list4 = dictionary.get_Item(current2);
					PhotoListLine photoListLine = null;
					for (int i = 0; i < list4.get_Count(); i++)
					{
						if (i % 4 == 0)
						{
							photoListLine = new PhotoListLine();
							list3.Add(photoListLine);
						}
						photoListLine.pictures[i % 4] = list4.get_Item(i);
					}
					MultiPhotoChooser.Group<PhotoListLine> group = new MultiPhotoChooser.Group<PhotoListLine>(current2, list3);
					tempListGroup.Add(group);
				}
			}
			if (tempListGroup.get_Count() > 2)
			{
				this.mListGroup.Add(tempListGroup.get_Item(0));
				this.mListGroup.Add(tempListGroup.get_Item(1));
				base.get_Dispatcher().BeginInvoke(delegate
				{
					for (int j = 2; j < tempListGroup.get_Count(); j++)
					{
						this.mListGroup.Add(tempListGroup.get_Item(j));
					}
				});
				return;
			}
			using (List<MultiPhotoChooser.Group<PhotoListLine>>.Enumerator enumerator3 = tempListGroup.GetEnumerator())
			{
				while (enumerator3.MoveNext())
				{
					MultiPhotoChooser.Group<PhotoListLine> current3 = enumerator3.get_Current();
					this.mListGroup.Add(current3);
				}
			}
		}
		private List<PictureAlbum> getAlbums()
		{
			List<PictureAlbum> list = new List<PictureAlbum>();
			PictureAlbum rootPictureAlbum = this.mediaLibrary.get_RootPictureAlbum();
			using (IEnumerator<PictureAlbum> enumerator = rootPictureAlbum.get_Albums().GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					PictureAlbum current = enumerator.get_Current();
					if (current.get_Pictures() != null && current.get_Pictures().get_Count() > 0)
					{
						list.Add(current);
					}
				}
			}
			if (rootPictureAlbum.get_Pictures() != null && rootPictureAlbum.get_Pictures().get_Count() > 0)
			{
				list.Add(rootPictureAlbum);
			}
			return list;
		}
		private void loadPicsOfAlbum(PictureAlbum album)
		{
			if (album == null || album == this.lastAlbum)
			{
				return;
			}
			this.lastAlbum = album;
			ObservableCollection<PhotoListLine> lines = new ObservableCollection<PhotoListLine>();
			List<PhotoListLine> tempLines = new List<PhotoListLine>();
			this.AlbumPicsListBox.set_ItemsSource(lines);
			PictureCollection pictures = album.get_Pictures();
			IEnumerable<Picture> enumerable = Enumerable.Reverse<Picture>(Enumerable.OrderBy<Picture, DateTime>(pictures, (Picture picture_0) => picture_0.get_Date()));
			int num = 0;
			PhotoListLine photoListLine = null;
			using (IEnumerator<Picture> enumerator = enumerable.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					Picture current = enumerator.get_Current();
					if (num % 4 == 0)
					{
						photoListLine = new PhotoListLine();
						tempLines.Add(photoListLine);
					}
					photoListLine.pictures[num % 4] = current;
					num++;
				}
			}
			if (tempLines.get_Count() > 5)
			{
				lines.Add(tempLines.get_Item(0));
				lines.Add(tempLines.get_Item(1));
				lines.Add(tempLines.get_Item(2));
				lines.Add(tempLines.get_Item(3));
				lines.Add(tempLines.get_Item(4));
				base.get_Dispatcher().BeginInvoke(delegate
				{
					for (int i = 5; i < tempLines.get_Count(); i++)
					{
						lines.Add(tempLines.get_Item(i));
					}
				});
				return;
			}
			using (List<PhotoListLine>.Enumerator enumerator2 = tempLines.GetEnumerator())
			{
				while (enumerator2.MoveNext())
				{
					PhotoListLine current2 = enumerator2.get_Current();
					lines.Add(current2);
				}
			}
		}
		public static void GoToThisPage(MultiPhotoChooserConfig mpcConfig, bool isRemoveMe = false)
		{
			ToolFunction.GotoPageForUserControl("/Source/UI/Util/MultiPhotoChooser/MultiPhotoChooser.xaml", new object[]
			{
				mpcConfig
			}, isRemoveMe);
		}
		public static MultiPhotoChooser GetCurrentPage()
		{
			PhoneApplicationFrame phoneApplicationFrame = Application.get_Current().get_RootVisual() as PhoneApplicationFrame;
			return phoneApplicationFrame.get_Content() as MultiPhotoChooser;
		}
		public bool SetSelectState(Picture picture, bool bSelect, ChooserImage imgView)
		{
			if (picture == null)
			{
				return false;
			}
			try
			{
				if (!ImageUtil.CheckImageFormat(picture.GetImage()))
				{
					MMMessageBox.Show(strings.ChatImgSendFormatError, true, "确定").ReturnEvent = new DlgReturnEvent(this.onCloseMsgBox);
					bool result = false;
					return result;
				}
			}
			catch (Exception)
			{
				MMMessageBox.Show(strings.ChatImgSendFormatError, true, "确定").ReturnEvent = new DlgReturnEvent(this.onCloseMsgBox);
				bool result = false;
				return result;
			}
			if (bSelect)
			{
				if (MultiPhotoChooser.sSelectedPictures.get_Count() >= this.config.CountLimit)
				{
					MMMessageBox.Show(string.Format(strings.MultiPhotoChooser_Limit, this.config.CountLimit), true, "确定").ReturnEvent = new DlgReturnEvent(this.onCloseMsgBox);
					return false;
				}
				MultiPhotoChooser.sSelectedPictures.Add(picture);
			}
			else
			{
				MultiPhotoChooser.sSelectedPictures.Remove(picture);
			}
			if (this.AlbumPicsLayout.get_Visibility() == null)
			{
				this.isChangedInAlbum = true;
			}
			else
			{
				this.lastAlbum = null;
			}
			this.updateTitleCount();
			if (bSelect)
			{
				ImageButton imageButton = new ImageButton();
				imageButton.ImgH = 88.0;
				imageButton.ImgW = 88.0;
				imageButton.set_Width(88.0);
				imageButton.set_Height(88.0);
				imageButton.set_Margin(new Thickness(8.0, 0.0, 0.0, 0.0));
				BitmapImage bitmapImage = new BitmapImage();
				bitmapImage.SetSource(picture.GetThumbnail());
				imageButton.Source = bitmapImage;
				this.resultPicLayout.get_Children().Add(imageButton);
				imageButton.set_Tag(picture);
				imageButton.add_Click(new RoutedEventHandler(this.resultPic_Click));
			}
			else
			{
				ImageButton imageButton2 = null;
				using (IEnumerator<UIElement> enumerator = this.resultPicLayout.get_Children().GetEnumerator())
				{
					while (enumerator.MoveNext())
					{
						UIElement current = enumerator.get_Current();
						ImageButton imageButton3 = current as ImageButton;
						if (imageButton3 != null)
						{
							if (!picture.Equals(imageButton3.get_Tag()))
							{
								continue;
							}
							imageButton2 = imageButton3;
						}
						break;
					}
				}
				if (imageButton2 != null)
				{
					this.resultPicLayout.get_Children().Remove(imageButton2);
				}
			}
			MultiPhotoChooser.HandlePicViewsMap(picture, bSelect, imgView);
			return true;
		}
		private void onCloseMsgBox(DlgReturnEventArg dlgReturnEventArg_0)
		{
			if (this.mBar != null && this.mBar.get_IsVisible())
			{
				this.mBar.set_IsVisible(false);
			}
		}
		private void updateTitleCount()
		{
			this.txtTitle.set_Text(strings.MultiPhotoChooser_Title + string.Format("({0}/{1})", MultiPhotoChooser.sSelectedPictures.get_Count(), this.config.CountLimit));
		}
		public static void HandlePicViewsMap(Picture picture, bool bSelect, ChooserImage imgView)
		{
			if (bSelect)
			{
				List<ChooserImage> list;
				if (!MultiPhotoChooser.pic_views_map.ContainsKey(picture))
				{
					list = new List<ChooserImage>();
					MultiPhotoChooser.pic_views_map.Add(picture, list);
				}
				else
				{
					list = MultiPhotoChooser.pic_views_map.get_Item(picture);
				}
				if (list != null && imgView != null)
				{
					list.Add(imgView);
					return;
				}
			}
			else
			{
				MultiPhotoChooser.pic_views_map.Remove(picture);
			}
		}
		private void resultOKButton_Click(object sender, EventArgs e)
		{
			if (MultiPhotoChooser.sSelectedPictures.get_Count() == 0)
			{
				return;
			}
			this.resultData = new MultiPhotoChooserResult();
			if (this.config.IsNeedRotate && MultiPhotoChooser.sSelectedPictures.get_Count() == 1)
			{
				if (this.mBar == null)
				{
					base.set_ApplicationBar(this.GetApplicationBar());
				}
				this.mBar.set_IsVisible(true);
				this.rotateLayout.set_Visibility(0);
				this.ContentPanel.set_Visibility(1);
				BitmapImage bitmapImage = new BitmapImage();
				bitmapImage.SetSource(MultiPhotoChooser.sSelectedPictures.get_Item(0).GetImage());
				this.rotateImage = new WriteableBitmap(bitmapImage);
				bitmapImage = new BitmapImage();
				bitmapImage.SetSource(MultiPhotoChooser.sSelectedPictures.get_Item(0).GetThumbnail());
				this.rotateThumb = new WriteableBitmap(bitmapImage);
				this.image_0.set_Source(this.rotateImage);
				return;
			}
			this.resultData.Pictures = new List<Picture>();
			this.resultData.Pictures.AddRange(MultiPhotoChooser.sSelectedPictures);
			this.closeAndReturn();
		}
		private void resultPic_Click(object sender, EventArgs e)
		{
			ImageButton imageButton = sender as ImageButton;
			if (imageButton == null || imageButton.get_Tag() == null)
			{
				return;
			}
			Picture picture = imageButton.get_Tag() as Picture;
			if (picture == null)
			{
				return;
			}
			if (MultiPhotoChooser.pic_views_map.ContainsKey(picture))
			{
				List<ChooserImage> list = MultiPhotoChooser.pic_views_map.get_Item(picture);
				using (List<ChooserImage>.Enumerator enumerator = list.GetEnumerator())
				{
					while (enumerator.MoveNext())
					{
						ChooserImage current = enumerator.get_Current();
						if (picture.Equals(current.mPicture))
						{
							current.SetSelected(false);
						}
					}
				}
				MultiPhotoChooser.pic_views_map.Remove(picture);
			}
			MultiPhotoChooser.sSelectedPictures.Remove(picture);
			this.resultPicLayout.get_Children().Remove(imageButton);
			if (this.AlbumPicsLayout.get_Visibility() == null)
			{
				this.isChangedInAlbum = true;
			}
			else
			{
				this.lastAlbum = null;
			}
			this.updateTitleCount();
		}
		public IApplicationBar GetApplicationBar()
		{
			if (this.mBar != null)
			{
				return this.mBar;
			}
			this.mBar = new ApplicationBar();
			this.mBar.set_IsMenuEnabled(true);
			this.mRotateButton = new ApplicationBarIconButton(new Uri("/Resource/Img/CommonUse/icon_rotate.png", 2));
			this.mRotateButton.set_Text(strings.Filter_Rotate_Image);
			this.mRotateButton.add_Click(new EventHandler(this.rotateButton_Click));
			this.mBar.get_Buttons().Add(this.mRotateButton);
			this.mOkBarButton = new ApplicationBarIconButton(new Uri("/Resource/Img/CommonUse/ico_save.png", 2));
			this.mOkBarButton.set_Text(strings.COM_Confirm);
			this.mOkBarButton.add_Click(new EventHandler(this.mOkBarButton_Click));
			this.mBar.get_Buttons().Add(this.mOkBarButton);
			this.mOkBarButton.set_IsEnabled(MultiPhotoChooser.sSelectedPictures.get_Count() > 0);
			return this.mBar;
		}
		private void mOkBarButton_Click(object sender, EventArgs e)
		{
			this.mPivotControl.set_Height(735.0);
			this.resultData = new MultiPhotoChooserResult();
			base.get_Dispatcher().BeginInvoke(delegate
			{
				this.mTurnAngle %= 360;
				if (this.mTurnAngle != 0)
				{
					this.resultData.SingleResult = new ResultPicture();
					this.rotateImage = MultiPhotoChooser.rotatePicture(this.rotateImage, this.mTurnAngle);
					this.rotateThumb = MultiPhotoChooser.rotatePicture(this.rotateThumb, this.mTurnAngle);
					Stream image = MultiPhotoChooser.bitmapToStream(this.rotateImage);
					Stream thumbnail = MultiPhotoChooser.bitmapToStream(this.rotateThumb);
					this.resultData.SingleResult.Image = image;
					this.resultData.SingleResult.Thumbnail = thumbnail;
				}
				else
				{
					this.resultData.Pictures = new List<Picture>();
					this.resultData.Pictures.AddRange(MultiPhotoChooser.sSelectedPictures);
				}
				this.closeAndReturn();
			});
		}
		private void closeAndReturn()
		{
			if (this.mBar != null)
			{
				this.mBar.set_IsVisible(false);
			}
			if (this.config.ForwardPageUri != null && this.config.ForwardPageUri.get_Length() > 0)
			{
				base.GoToPage(this.config.ForwardPageUri, new object[]
				{
					this.resultData
				}, true);
				return;
			}
			if (this.config.MultiPhotoChooserCallBack != null)
			{
				base.GoBack();
				base.get_Dispatcher().BeginInvoke(delegate
				{
					this.config.MultiPhotoChooserCallBack(this.resultData);
				});
			}
		}
		private void rotateButton_Click(object sender, EventArgs e)
		{
			this.mTurnAngle += 90;
			Duration duration = new Duration(TimeSpan.FromMilliseconds(500.0));
			Storyboard storyboard = new Storyboard();
			storyboard.set_Duration(duration);
			DoubleAnimation doubleAnimation = new DoubleAnimation();
			doubleAnimation.set_Duration(duration);
			storyboard.get_Children().Add(doubleAnimation);
			RotateTransform rotateTransform = new RotateTransform();
			Storyboard.SetTarget(doubleAnimation, rotateTransform);
			Storyboard.SetTargetProperty(doubleAnimation, new PropertyPath("Angle", new object[0]));
			doubleAnimation.set_To(new double?((double)this.mTurnAngle));
			doubleAnimation.set_From(new double?((double)(this.mTurnAngle - 90)));
			this.image_0.set_RenderTransform(rotateTransform);
			this.image_0.set_RenderTransformOrigin(new Point(0.5, 0.5));
			storyboard.Begin();
		}
		private static Stream bitmapToStream(BitmapSource image)
		{
			MemoryStream memoryStream = new MemoryStream();
			WriteableBitmap writeableBitmap = new WriteableBitmap(image);
			Extensions.SaveJpeg(writeableBitmap, memoryStream, image.get_PixelWidth(), image.get_PixelHeight(), 0, 100);
			memoryStream.Seek(0L, 0);
			return memoryStream;
		}
		private static WriteableBitmap rotatePicture(WriteableBitmap image, int angle)
		{
			WriteableBitmap writeableBitmap = null;
			if (angle == 90)
			{
				writeableBitmap = new WriteableBitmap(image.get_PixelHeight(), image.get_PixelWidth());
				for (int i = 0; i < image.get_PixelHeight(); i++)
				{
					for (int j = 0; j < image.get_PixelWidth(); j++)
					{
						writeableBitmap.get_Pixels()[writeableBitmap.get_PixelWidth() * j + (writeableBitmap.get_PixelWidth() - 1 - i)] = image.get_Pixels()[image.get_PixelWidth() * i + j];
					}
				}
			}
			else
			{
				if (angle == 180)
				{
					writeableBitmap = new WriteableBitmap(image.get_PixelWidth(), image.get_PixelHeight());
					for (int k = 0; k < image.get_PixelHeight(); k++)
					{
						for (int l = 0; l < image.get_PixelWidth(); l++)
						{
							writeableBitmap.get_Pixels()[writeableBitmap.get_PixelWidth() * (writeableBitmap.get_PixelHeight() - 1 - k) + (writeableBitmap.get_PixelWidth() - 1 - l)] = image.get_Pixels()[image.get_PixelWidth() * k + l];
						}
					}
				}
				else
				{
					if (angle == 270)
					{
						writeableBitmap = new WriteableBitmap(image.get_PixelHeight(), image.get_PixelWidth());
						for (int m = 0; m < image.get_PixelHeight(); m++)
						{
							for (int n = 0; n < image.get_PixelWidth(); n++)
							{
								writeableBitmap.get_Pixels()[writeableBitmap.get_PixelWidth() * (writeableBitmap.get_PixelHeight() - 1 - n) + m] = image.get_Pixels()[image.get_PixelWidth() * m + n];
							}
						}
					}
				}
			}
			return writeableBitmap;
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/UI/Util/MultiPhotoChooser/MultiPhotoChooser.xaml", 2));
			this.LayoutRoot = (Grid)base.FindName("LayoutRoot");
			this.ContentPanel = (Grid)base.FindName("ContentPanel");
			this.txtTitle = (TextBlock)base.FindName("txtTitle");
			this.MainLayout = (Grid)base.FindName("MainLayout");
			this.mPivotControl = (Pivot)base.FindName("mPivotControl");
			this.btnTimeLineTab = (Button)base.FindName("btnTimeLineTab");
			this.timeLineView = (Grid)base.FindName("timeLineView");
			this.mTimeLineLongList = (LongListSelector)base.FindName("mTimeLineLongList");
			this.btnAlbumsTab = (Button)base.FindName("btnAlbumsTab");
			this.AlbumsView = (Grid)base.FindName("AlbumsView");
			this.AlbumsLayout = (WrapPanel)base.FindName("AlbumsLayout");
			this.AlbumPicsLayout = (StackPanel)base.FindName("AlbumPicsLayout");
			this.txtAlbumTitle = (DynamicTextBlock)base.FindName("txtAlbumTitle");
			this.AlbumPicsListBox = (ListBox)base.FindName("AlbumPicsListBox");
			this.resultPicScrollViewer = (ScrollViewer)base.FindName("resultPicScrollViewer");
			this.resultPicLayout = (StackPanel)base.FindName("resultPicLayout");
			this.resultOKButton = (ImageButton)base.FindName("resultOKButton");
			this.rotateLayout = (ScrollViewer)base.FindName("rotateLayout");
			this.image_0 = (Image)base.FindName("img");
		}
	}
}
